import java.lang.String;

/**
 * This class contains the definition of a node, used to implicitly search the
 * graph for a way to the end
 */
public class Node
{
    private Position p;
    private String path;
    private Board b;
    private int weight;
    private String bs;
    
    /**
    * Constructor for a node, using only position and path. This can be used
    * when a path that doesn't modify the board wants to be found
    *
    * @param p Position object indicating the position to be visited
    * @param path Path that has been taken to get to this point
    */
    public Node(Position p, String path)
    {
        this.p = p;
        this.path = path;
    }

   /**
    * Constructor for a node, using all of it's attributer. This can be used
    * when a path that modifies the board wants to be found
    *
    * @param p Position object indicating the position to be visited
    * @param path Path that has been taken to get to this point
    */
    public Node(Position p, String path, Board b)
    {
        this.p = p;
        this.path = path;
        this.b = b;
        this.bs = b.getKey();
    }
    
    /**
     * Constructor for a node used for marking-BFS
     *
     * @param p Position object indicating the position to be visited
     * @param path Path that has been taken to get to this point
     */
     public Node(Position p)
     {
         this.p = p;
     }
    /**
    * Recalculates the value of the weight that this node has. This value is
    * important to calculate the nodes priority.
    */
    public void estimateWeight()
    {
        this.weight = 0;
        int [][]dist = this.b.getDistances();
        for(Position box : this.b.getBoxes())
            weight += dist[box.getX()][box.getY()];
        
        weight += 100*this.b.getEmptyGoals().size();
    }


    /**
    * Creates a copy of the class
    *
    * @return A new Node that has the same attributes as this
    */
	public Node copy() 
    {
		return new Node(getP(), getPath(), getB());
	}
    //Getters for the class
    public Position getP(){return this.p;}
    public String getPath(){return this.path;}
    public Board getB(){return this.b;}
    public int getWeight(){return this.weight;}
    public String getBs(){return this.bs;}
    
}
